﻿using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using OnWork.DataCenter.BLL.TaskScheduler;
using System.Diagnostics.CodeAnalysis;

namespace OnWork.DataCenter.Shared
{
    /// <summary>
    ///
    /// </summary>
    public sealed partial class App
    {
        /// <summary>
        ///
        /// </summary>
        [Inject]
        [NotNull]
        private IJSRuntime? JSRuntime { get; set; }

        /// <summary>
        /// 后台任务
        /// </summary>
        [Inject]
        private OnWork.DataCenter.BLL.TaskScheduler.TaskSchedulerBLL taskSchedulerBLL { get; set; }

        /// <summary>
        ///
        /// </summary>
        /// <param name="firstRender"></param>
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            await base.OnAfterRenderAsync(firstRender);

            //初始化定时任务
            if (firstRender && taskSchedulerBLL != null)
            {
                await taskSchedulerBLL.InitJobs();
            }

            if (firstRender && OperatingSystem.IsBrowser())
            {
                await JSRuntime.InvokeVoidAsync("$.loading");
            }
        }
    }
}